-- create indexes
CREATE INDEX type ON `${bucket}`(`_class`)
    WITH { "defer_build" : true };
<%_ if (!skipUserManagement) { _%>

CREATE INDEX user_mail ON `${bucket}`(email)
    WHERE `_class` = "<%= packageName %>.domain.<%= asEntity('User') %>"
    WITH { "defer_build" : true };

<% if (authenticationType === 'session') { %>

CREATE INDEX token_login ON `${bucket}`(login)
    WHERE `_class` = "<%= packageName %>.domain.PersistentToken"
    WITH { "defer_build" : true };

CREATE INDEX token_date ON `${bucket}`(tokenDate)
    WHERE `_class` = "<%= packageName %>.domain.PersistentToken"
    WITH { "defer_build" : true };<% } %>
<%_ } _%>

-- build indexes asynchronously
BUILD INDEX ON `${bucket}`(type<% if (!skipUserManagement) { %>, user_mail<% if (authenticationType === 'session') { %>, token_login, token_date<% } %><% } %>);
